﻿using log4net.Appender;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using log4net.Core;
using Newtonsoft.Json;
using System.Net.Http;
using System.Text;
using TongTongMall.MallWeb.Core.Instance;
using System.Net.Http.Headers;
using System.Configuration;
using Newtonsoft.Json.Linq;
using TongTongMall.UI;
using TongTongMall.MallWeb.Core.Enums;
using TongTongMall.MallWeb.Application.Configuration;
using TongTongMall.MallWeb.Application.DingTalkRob;

namespace TongTongMall.MallWeb.WebApi.Core.Logger
{
    public class DingDingTalkLog4netAppender : AppenderSkeleton
    {
        protected override void Append(LoggingEvent loggingEvent)
        {
            if (loggingEvent.Level == Level.Error)
            {
                var _dingTalkRobService = new DingTalkRobService();
                var requestJson = JsonConvert.SerializeObject(new
                {
                    msgtype = "text",
                    text = new { content = $"{loggingEvent.ExceptionObject}" },
                    at = new { atMobiles = new List<string>(), isAtAll = false }
                });
                _dingTalkRobService.SendDingTalkRob(requestJson);
            }
        }
    }
}